<template>
  <div class="problem-item" @click="handleClick">
    <div class="problem-info">
      <div class="problem-status">
        <span 
          v-if="problemStore.isProblemSolved(problem.problemId)" 
          style="color: #52c41a; font-size: 16px; display: block"
        >
          ✓
        </span>
      </div>
      <span class="problem-id">{{ problem.problemId }}</span>
      <span class="problem-title">{{ problem.problemTitle }}</span>
    </div>
    <div class="problem-meta">
      <span class="problem-ac-rate">{{ Number(problem.acceptanceRate).toFixed(2) }}%</span>
      <span class="problem-difficulty" :class="difficultyClass">
        {{ difficultyText }}
      </span>
    </div>
  </div>
</template>

<script>
import { useProblemStore } from '@/stores/problem'

export default {
  name: 'ProblemListItem',
  props: {
    problem: {
      type: Object,
      required: true
    }
  },
  computed: {
    difficultyClass() {
      return {
        'easy': this.problem.difficultyLevel === 1,
        'medium': this.problem.difficultyLevel === 2,
        'hard': this.problem.difficultyLevel === 3
      }
    },
    problemStore() {
      return useProblemStore()
    },
    difficultyText() {
      return ['简单', '中等', '困难'][this.problem.difficultyLevel - 1] || '未知'
    }
  },
  methods: {
    handleClick() {
      if (!this.problem.problemId) {
        console.error('Problem ID is missing', this.problem)
        return
      }
      this.$router.push({
        name: 'problem-detail',
        params: { id: String(this.problem.problemId) }
      })
    }
  }
}
</script>

<style scoped>
.problem-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.3s;
}

.problem-item:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.problem-info {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 8px;
}

.problem-status {
  width: 24px;
  min-width: 24px;
  display: flex;
  justify-content: center;
}

.problem-id {
  color: #999;
  width: 40px;
  margin-left: 8px;
}

.problem-title {
  font-weight: 500;
  flex: 1;
}

.problem-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.problem-ac-rate {
  color: #666;
  font-size: 14px;
  min-width: 50px;
  text-align: right;
}

.problem-difficulty {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  min-width: 40px;
  text-align: center;
}

.easy {
  background: #f6ffed;
  color: #52c41a;
  border: 1px solid #b7eb8f;
}

.medium {
  background: #e6f7ff;
  color: #1890ff;
  border: 1px solid #91d5ff;
}

.hard {
  background: #fff2f0;
  color: #f5222d;
  border: 1px solid #ffa39e;
}

.problem-status {
  margin-left: 8px;
  min-width: 24px;
}
</style>
